package com.alex.algorithm.easy;

public class MergedSortedArray {

    public static void main(String[] args) {
        int[] target = {1,2,3,0,0,0};
        int[] source = {2,5,6};
        merge(target, 3, source, 3);
        for (int i = 0; i < 6; ++i) {
            System.out.println(target[i]);
        }
    }

    public static void merge(int[] target, int m, int[] source, int n) {
        if (n <= 0 || m <= 0){
            return;
        }
        int current = target.length - 1;
        int mCur = m - 1;
        int nCur = n - 1;
        while (current >= 0) {
            if (nCur == -1) {
                return;
            }
            if (target[mCur] <= source[nCur]) {
                target[current--] = source[nCur--];
            }else {
                target[current--] = target[mCur--];
            }
            System.out.println("mCur:" + mCur + ",nCur:" + nCur);
        }
    }
}
